﻿using NUnit.Framework;
using AdventureWorks.DataAccess.repository;
using System.Linq;
using AdventureWorks.DataAccess.SearchCriterias;
using AdventureWorks.Domain;

namespace AdventureWorks.DataAccess.Test.repository
{

    [TestFixture]
    public class ProductRepositoryTest : RepositoryTestBase<ProductRepository>
    {
        [Test]
        public void Should_return_correct_subcategory()
        {
            var search = new ProductSearchCriteria { ProductNumber = "FR-R38B-58" };
            var product = repository.GetProducts(session, search).Single();
            Assert.AreEqual("Road Frames", product.SubCategory.Name);
            Assert.AreEqual(ProductCategory.Components, product.SubCategory.Category);
        }

        [Test]
        public void When_search_with_no_criterias_return_all_record()
        {
            var search = new ProductSearchCriteria { };
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(504, products);
        }

        [Test]
        public void When_search_by_name_should_return_correct_result()
        {
            var search = new ProductSearchCriteria { Name = "LL Road Frame - Black, 58"};
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(1, products);
        }

        [Test]
        public void When_search_by_number_should_return_correct_result()
        {
            var search = new ProductSearchCriteria { ProductNumber = "FR-R38B-58" };
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(1, products);
        }

        [Test]
        public void When_search_by_color_should_return_correct_result()
        {
            var search = new ProductSearchCriteria { Color = "Black" };
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(93, products);
        }

        [Test]
        public void When_search_by_standardcost_should_return_correct_result()
        {
            var search = new ProductSearchCriteria { StandardCost = 98.77m };
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(3, products);
        }

        [Test]
        public void When_search_by_category_should_return_correct_result()
        {
            var search = new ProductSearchCriteria { Category = (int?)ProductCategory.Bikes };
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(97, products);
        }

        [Test]
        public void When_search_by_subcategory_should_return_correct_result()
        {
            var search = new ProductSearchCriteria { Category = (int?)ProductCategory.Bikes, SubCategory = "Mountain Bikes" };
            var products = repository.GetProducts(session, search).Count();
            Assert.AreEqual(32, products);
        }


        //[Test]
        //public void when_refering_to_price_history_list_should_return_list()
        //{
        //    var search = new ProductSearchCriteria { ProductNumber = "HL-U509-R" };
        //    var product = repository.GetProducts(session, search).Single();
        //    Assert.IsNotNull(product.ProductPriceHistory);
        //    Assert.AreEqual(3, product.ProductPriceHistory.Count);
        //    Assert.Contains(34.99d, product.ProductPriceHistory.Select(x => x.ListPrice).ToList());
        //}

    }
}
